package controller;

import pojo.Classroom;
import org.junit.Test;
import service.ClassroomService;
import service.ClassroomServiceImpl;

import java.util.ArrayList;

public class ClassroomController {
    private ClassroomService service = new ClassroomServiceImpl();
    /*
        查询所有班级信息
     */
    @Test
    public void findAll() {
        ArrayList<Classroom> list = service.findAll();
        for(Classroom classroom : list) {
            System.out.println(classroom);
        }
    }

    /*
        条件查询，根据id查询班级信息
     */
    @Test
    public void findById() {
        Classroom classroom = service.findById(1);
        System.out.println(classroom);
    }

    @Test
    public void findByIdReturnBoolean(){
        System.out.println(service.findByIdReturnBoolean(1));
    }

    /*
        添加班级信息
     */
    @Test
    public void insert() {
        Classroom classroom = new Classroom(4,"通信工程");
        int result = service.insert(classroom);

        if(result!=0) {
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改班级信息
     */
    @Test
    public void update() {
        Classroom classroom = service.findById(3);
        classroom.setClassName("信安");

        int result = service.update(classroom);

        if(result != 0) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

}
